<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.min.js"></script>

    <style>
        .kewuae{
            width: 100px;
            height: 100px;
            margin-top: 10px;
        }
    </style>
    <script>
        function coursePptChange(e){
            var file = document.querySelector('input[type=file]').files[0];

            var reader = new FileReader();
            reader.onloadend = function () {
                $("#pptPic").attr("style","display:block");
                $("#pptPic").attr("src",reader.result);
                console.log(reader.result);

            }
            if (file) {
                reader.readAsDataURL(file);
            }

        }

        function kewua(){
            //用户一进来的密码
            var chushi= $('#chadianno').data('id')
            //要修改的密码
            var password=$('#password').val();
            var mim="";
            if(chushi==password){
                mim="";
            }else{
                mim=password;
            }
            var username=$('#username').val();
            var pptPic=$('#pptPic').attr("src");
            $.post("${pageContext.request.contextPath}/modifyServlet",{username:username,password:mim,pptPic:pptPic},function(result){
                if(result=="相同"){
                    var txt = "相同:M"+$("#pptPic").attr("src");
                    parent.GetChildValue(txt);
                }else if(result=="不相同"){
                    var txt = "不相同:M 一点也不相同";
                    parent.GetChildValue(txt);
                }else if (result=='true'){
                    $('#password').val("");
                    $('#pptPic').attr("src","");
                    $('#pptPic').attr("style","display:none");
                    var txt = "true";
                    parent.GetChildValue(txt);
                }else if (result=="false") {
                    alert("修改失败")
                }
            });
        }
    </script>
</head>
<body style="margin-left: 20px;margin-top: 20px;min-height: 800px;">
    <div style="width: 100%;font-size: 20px;font-weight: bold;margin-top: 40px">修改资料</div>
    <form style="margin-top: 20px" method="POST"  action="${pageContext.request.contextPath}/modifyServlet">
        <div class="form-group">
            <label for="username">您的账号</label>
            <input type="text" style="width: 300px" readonly=”readonly” value="${sessionScope.usersList.username}" id="username" name="username" class="form-control"  aria-describedby="emailHelp">
        </div>

        <div class="form-group" id="chadianno" data-id="${sessionScope.usersList.password}">
            <label for="password">修改密码</label>
            <input type="password" style="width: 300px" class="form-control" id="password" name="password">
        </div>
        <div class="form-group">
            <label for="editPptPic">修改头像</label>
            <input type="file" id="editPptPic" onchange="coursePptChange(this)" value="" accept=".gif,.jpg,.jpeg,.png"  name="pptPic" class="form-control-file" style="width:200px;">
            <img style="display: none" src="" id="pptPic" class="kewuae">
        </div>
        <button type="button" onclick="kewua()" class="btn btn-primary">提交</button>
    </form>
</body>
</html>
